package com.ldcc.report_system.util;


import android.text.TextUtils;

import com.ldcc.report_system.ApplicationConfig;
import com.ldcc.report_system.ReportApplication;

/**
 * @author wwj[yeshengkele@outlook.com]
 * @description 处理服务器工具类
 */
public class ServerUtil {


    /**
     * @param serverAddress 服务器地址
     * @param port          端口
     * @description 保存服务器地址
     */
    public static void saveServerUrl(String serverAddress, String port) {
        SharedPreferencesUtils.setParam(ReportApplication.getContext(), ApplicationConfig.SERVER_ADDRESS_KEY, serverAddress);
        SharedPreferencesUtils.setParam(ReportApplication.getContext(), ApplicationConfig.SERVER_PORT_KEY, port);
    }

    /**
     * @return 服务器地址
     * @description 获得服务器链接地址
     */
    public static String getServerUrl() {
        String serverAddress = (String) SharedPreferencesUtils.getParam(ReportApplication.getContext(), ApplicationConfig.SERVER_ADDRESS_KEY, "");
        String port = (String) SharedPreferencesUtils.getParam(ReportApplication.getContext(), ApplicationConfig.SERVER_PORT_KEY, "");
        return ApplicationConfig.HTTP_KEY + serverAddress + ":" + port;
    }

    /**
     * @description 判断是否存在网络配置
     */
    public static boolean checkServerUrl() {
        String serverAddress = (String) SharedPreferencesUtils.getParam(ReportApplication.getContext(),
                ApplicationConfig.SERVER_ADDRESS_KEY, "");
        String port = (String) SharedPreferencesUtils.getParam(ReportApplication.getContext(),
                ApplicationConfig.SERVER_PORT_KEY,
                "");
        if (TextUtils.isEmpty(serverAddress)) {
            return false;
        }
        if (TextUtils.isEmpty(port)) {
            return false;
        }
        return true;
    }


}
